from appium import webdriver
import time
from appium.webdriver.common.appiumby import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# 连接配置
# 连接配置信息
des = {
    "platformName": "Android",
    "platformVersion": "7.1.2",
    "deviceName": "emulator-5554",
    "appPackage": "com.android.settings",
    "appActivity": ".Settings"
}
# 初始化驱动对象
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", des)
# # 隐式等待
# driver.implicitly_wait(10)

# 输入坚果
print("开始查找元素。。。。。。。。。")
start_time = time.time()
try:
    # element = driver.find_element(By.CLASS_NAME, "android.widget.EditText")
    # 显式等待, (By.CLASS_NAME, "android.widget.EditText")
    element = WebDriverWait(driver, 10, 0.5).until(EC.presence_of_element_located((By.CLASS_NAME, "android.widget.EditText")))
    element.send_keys("坚果")
except:
    print("元素未找到。。。。")
end_time = time.time()

print("查找元素耗时：{}".format(end_time-start_time))
driver.quit()